package
{
	import com.feng.ControllerCenter;
	import com.feng.FengData;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;

	/**
	 * @author 风之守望者
	 */
	public class TestFeng extends Sprite
	{
		private var instance:*;

		private var myFileStream:FileStream = new FileStream();

		private var breakpoints:Array = [257];

		public function TestFeng()
		{
			FengData.showData = false;

			instance = new ControllerCenter();

			var myFile:File = File.documentsDirectory.resolvePath(FengData.dataPath);
			myFileStream.addEventListener(Event.COMPLETE, completed);
			myFileStream.openAsync(myFile, FileMode.READ);
		}

		private function completed(event:Event):void
		{
			var data:String = myFileStream.readMultiByte(myFileStream.bytesAvailable, "iso-8859-1");

			var dataArr:Array = data.split("\n");

			for (var i:int = 0; i < dataArr.length; i++)
			{
				if (breakpoints.indexOf(i) != -1)
				{
					"断点处";
				}
				if (dataArr[i].length > 0)
				{
					FengData.showDataIndex++;
					var action:Array = JSON.parse(dataArr[i]) as Array;
					doAction(action);
				}
			}
		}

		private function doAction(action:Array):void
		{
			switch (action.length)
			{
				case 1:
					instance[action[0]]();
					break;
				case 2:
					instance[action[0]](action[1]);
					break;
				case 3:
					instance[action[0]](action[1], action[2]);
					break;
				case 4:
					instance[action[0]](action[1], action[2], action[3]);
					break;
				case 5:
					instance[action[0]](action[1], action[2], action[3], action[4]);
					break;
				case 6:
					instance[action[0]](action[1], action[2], action[3], action[4], action[5]);
					break;
				case 7:
					instance[action[0]](action[1], action[2], action[3], action[4], action[6]);
					break;
				default:
					throw new Error("已经处理不了了");
					break;
			}
		}

	}
}
